package com.hobart.learning.lagou.edu.utils;

import com.alibaba.druid.pool.DruidDataSource;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author ：hobart
 * @date ：Created in 2021-1-28 16:34
 * @description： 连接池 工具
 * @version: 1.0
 */
public class DruidUtils {
    private DruidUtils(){
    }

    private static DruidDataSource druidDataSource = new DruidDataSource();

    private static Properties pps = new Properties();

    static {

        try {
            pps.load(DruidUtils.class.getResourceAsStream("/jdbc.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        final String driverClass = pps.getProperty("jdbc.driverClass");
        final String jdbcUrl = pps.getProperty("jdbc.jdbcUrl");
        final String username = pps.getProperty("jdbc.username");
        final String password = pps.getProperty("jdbc.password");
        druidDataSource.setDriverClassName(driverClass);
        druidDataSource.setUrl(jdbcUrl);
        druidDataSource.setUsername(username);
        druidDataSource.setPassword(password);
    }

    public static DruidDataSource getInstance() {
        return druidDataSource;
    }

}
